﻿//using System;
//using System.Collections.Generic;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
//using System.Windows;
//using Microsoft.WVB.Framework;
//using Microsoft.WVB.Services;
//using Microsoft.WVB.Framework.Entities;

//namespace Microsoft.WVB.UnitTest.Client
//{
//    [TestClass]
//    public class Services_MembershipAndProfileTest
//    {
//        IDIContainer dic = null;

//        public String username { get; set; }

//        [TestInitialize]
//        public void TestMethod()
//        {
//            IoC.InitializeApplicationResources(App.Current);
//            username = "JohnDOe";

//            //Register Services here 
//            dic = IoC.GetCurrentApplicationDIContainer();

//            //READ from XML Configuration file (erik)
//            dic.Configuration["UserServices_MembershipPath"] = "http://localhost:8080/Membership.svc";
//            dic.Configuration["UserServices_ProfilePath"] = "http://localhost:8080/Profile.svc";
//            dic.Configuration["DataService_EPG"] = new Uri("http://localhost:8080/CDNDataService.svc");

//            //Services
//            dic.Register<IProfileProvider<ProfileInfo>>((c) => new MICProfileProvider(c.GetNamedConfigurationItem<string>("UserServices_ProfilePath")));
//            dic.Register<IMembershipProvider<MembershipUser>>((c) => new MICMembershipProvider(c.GetNamedConfigurationItem<string>("UserServices_MembershipPath")));
//            dic.Register<IUser>((c) => new User<MembershipUser, ProfileInfo>());
//        }


//        /// <summary>
//        /// Tests need to be chained since they are all asynchronous
//        /// This is the reson why only one has a TestMedthod attribute. Do not run all the test in a row
//        /// or you will have errors
//        /// </summary>
//        [TestMethod()]
//        [TestProperty("username", "JohnDoe")]
//        [TestProperty("password", "!passw0rd!")]
//        public void CreateMembershipUser()
//        {
//            IMembershipProvider<MembershipUser> m = dic.GetCreate<IMembershipProvider<MembershipUser>>();
//            m.CreateUserCompleted += delegate(AcquireCompletedEventArgs<MembershipUser> e)
//            {
//                Assert.IsNull(e.Error);
//                Assert.AreEqual(e.Result.UserName,username, false);
//                Assert.AreEqual(e.Result.Email, "johnDoe@live.com", false);
//                this.ValidateMembershipCredentials();
//            };

//            m.CreateUserAsync(username, "!passw0rd!", "johnDoe@live.com");
//        }

//        public void ValidateMembershipCredentials()
//        {
//            IMembershipProvider<MembershipUser> m = dic.GetCreate<IMembershipProvider<MembershipUser>>();
//            m.ValidateUserCompleted += delegate(object sender, NotifyActionCompletedEventArgs e)
//            {
//                Assert.IsNull(e.Error);
//                Assert.IsTrue(e.Result);
//                this.GetMembershipUser();
//            };

//            m.ValidateUserAsync(username, "!passw0rd!");
//        }

//        public void GetMembershipUser()
//        {
//            IMembershipProvider<MembershipUser> m = dic.GetCreate<IMembershipProvider<MembershipUser>>();
//            m.GetUserCompleted += delegate(AcquireCompletedEventArgs<MembershipUser> e)
//            {
//                Assert.AreEqual(e.Error, null);
//                Assert.AreEqual(e.Result.UserName, username, false);
//                Assert.AreEqual(e.Result.Email, "johnDoe@live.com", false);
//                this.UpdateMembershipUser();
//            };

//            m.GetUserAsync(username);
//        }

//        public void UpdateMembershipUser()
//        {
//            IMembershipProvider<MembershipUser> m = dic.GetCreate<IMembershipProvider<MembershipUser>>();
//            m.UpdateUserCompleted += delegate(object sender, NotifyActionCompletedEventArgs e)
//            {
//                Assert.IsNull(e.Error);
//                Assert.AreEqual(e.Action, Microsoft.WVB.Framework.Action.Update);
//                Assert.IsTrue(e.Result);
//                this.CreateProfileInfo();
//            };

//            MembershipUser u = new MembershipUser();
//            u.UserName = username;
//            u.Email = "JohnDoe@hotmail.com";
//            m.UpdateUserAsync(u);
//        }

//        public void CreateProfileInfo()
//        {
//            IProfileProvider<ProfileInfo> p = dic.GetCreate<IProfileProvider<ProfileInfo>>();

//            ProfileInfo profile = new ProfileInfo(username);
//            profile.BirthDate = new DateTime(1973, 1, 1);
//            profile.CompanySize = 50000;
//            profile.Country = "United States";
//            profile.FirstName = "John";
//            profile.Gender = Gender.Male;
//            profile.Income = 1.0;
//            profile.Industry = "Computer Sciences";
//            profile.Interests = "Philosophy, Xbox360, Cars";
//            profile.JobTitle = "Unknown";
//            profile.LastName = "Doe";
//            profile.Level = ProfileLevel.Registered;
//            profile.ZipCode = 95678;

//            p.CreateProfileCompleted += delegate(AcquireCompletedEventArgs<ProfileInfo> e)
//            {
//                Assert.IsNull(e.Error);
//                Assert.AreEqual(profile.BirthDate, e.Result.BirthDate);
//                Assert.AreEqual(profile.CompanySize, e.Result.CompanySize);
//                Assert.AreEqual(profile.Country, e.Result.Country);
//                Assert.AreEqual(profile.FirstName, e.Result.FirstName);
//                Assert.AreEqual(profile.Gender, e.Result.Gender);
//                Assert.AreEqual(profile.Income, e.Result.Income);
//                Assert.AreEqual(profile.Industry, e.Result.Industry);
//                Assert.AreEqual(profile.Interests, e.Result.Interests);
//                Assert.AreEqual(profile.JobTitle, e.Result.JobTitle);
//                Assert.AreEqual(profile.LastName, e.Result.LastName);
//                Assert.AreEqual(profile.Level, e.Result.Level);
//                Assert.AreEqual(profile.Username, e.Result.Username);
//                Assert.AreEqual(profile.ZipCode, e.Result.ZipCode);
//                this.GetProfileInfo();
//            };

//            p.CreateProfileAsync(profile);
//        }

//        public void GetProfileInfo()
//        {
//            IProfileProvider<ProfileInfo> p = dic.GetCreate<IProfileProvider<ProfileInfo>>();

//            p.GetProfileCompleted += delegate(AcquireCompletedEventArgs<ProfileInfo> e)
//            {
//                Assert.IsNull(e.Error);
//                Assert.AreEqual(new DateTime(1973, 1, 1), e.Result.BirthDate);
//                Assert.AreEqual(50000, e.Result.CompanySize);
//                Assert.AreEqual("United States", e.Result.Country);
//                Assert.AreEqual("John", e.Result.FirstName);
//                Assert.AreEqual(Gender.Male, e.Result.Gender);
//                Assert.AreEqual(1.0, e.Result.Income);
//                Assert.AreEqual("Computer Sciences", e.Result.Industry);
//                Assert.AreEqual("Philosophy, Xbox360, Cars", e.Result.Interests);
//                Assert.AreEqual("Unknown", e.Result.JobTitle);
//                Assert.AreEqual("Doe", e.Result.LastName);
//                Assert.AreEqual(ProfileLevel.Registered, e.Result.Level);
//                Assert.AreEqual(username, e.Result.Username);
//                Assert.AreEqual(95678, e.Result.ZipCode);
//                this.UpdateProfileInfo();
//            };

//            p.GetProfileAsync(username);
//        }

//        public void UpdateProfileInfo()
//        {
//            IProfileProvider<ProfileInfo> p = dic.GetCreate<IProfileProvider<ProfileInfo>>();

//            ProfileInfo profile = new ProfileInfo(username);
//            profile.BirthDate = new DateTime(1973, 1, 1);
//            profile.CompanySize = 50000;
//            profile.Country = "United States";
//            profile.FirstName = "John";
//            profile.Gender = Gender.Male;
//            profile.Income = 2.0;
//            profile.Industry = "Computer Sciences";
//            profile.Interests = "Philosophy, Xbox360, Cars";
//            profile.JobTitle = "Taxi Driver";
//            profile.LastName = "Doe";
//            profile.Level = ProfileLevel.Registered;
//            profile.ZipCode = 95678;

//            p.UpdateProfileCompleted += delegate(object sender, NotifyActionCompletedEventArgs e)
//            {
//                Assert.IsNull(e.Error);
//                Assert.IsTrue(e.Result);
//                Assert.AreEqual(e.Action, Microsoft.WVB.Framework.Action.Update);
//                this.DeleteProfileInfo();
//            };

//            p.UpdateProfileAsync(profile);
//        }

//        public void DeleteProfileInfo()
//        {
//            IProfileProvider<ProfileInfo> p = dic.GetCreate<IProfileProvider<ProfileInfo>>();
//            p.DeleteProfileCompleted += delegate(object sender, NotifyActionCompletedEventArgs e)
//            {
//                Assert.IsNull(e.Error);
//                Assert.IsTrue(e.Result);
//                Assert.AreEqual(e.Action, Microsoft.WVB.Framework.Action.Delete);
//                this.DeleteMembershipUser();
//            };

//            p.DeleteProfileAsync(username);
//        }

//        public void DeleteMembershipUser()
//        {
//            IMembershipProvider<MembershipUser> m = dic.GetCreate<IMembershipProvider<MembershipUser>>();
//            m.DeleteUserCompleted += delegate(object sender, NotifyActionCompletedEventArgs e)
//            {
//                Assert.IsNull(e.Error);
//                Assert.AreEqual(e.Action, Microsoft.WVB.Framework.Action.Delete);
//                Assert.IsTrue(e.Result);
//            };

//            m.DeleteUserAsync(username);
//        }

//    }
//}
